package zuosheng.day1;

/**
 * @author lj
 * @Description: 小的数和-遍历
 * @date 2020-10-31 13:29
 * @QQ 851477108
 */


public class xiaoshuhe {
    public static void main(String[] args){
        int[] arr = {1,3,4,2,5};
        int sum = sort(arr);
        System.out.println(sum);
    }

    private static int sort(int[] arr) {
        if (arr == null || arr.length < 2)
            return 0;
        int sum = 0;
        for (int i = 1; i < arr.length; i++) {
            for (int j = i ; j >= 0 ; j--){
                if (arr[j]<arr[i]){
                    sum += arr[j];
                }
            }
        }
        return sum;
    }
}
